package com.yanqu.road.server.gameplayer.module.activity.silkroad;

import com.yanqu.road.dao.impl.player.UserSilkRoadDaoImpl;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.silkroad.SilkRoadFindResult;
import com.yanqu.road.entity.activity.silkroad.SilkRoadGain;
import com.yanqu.road.entity.activity.silkroad.SilkRoadPlaceProgressInfo;
import com.yanqu.road.entity.activity.silkroad.UserSilkRoadData;
import com.yanqu.road.entity.activity.silkroad.config.SilkRoadEventConfig;
import com.yanqu.road.entity.activity.silkroad.config.SilkRoadItemConfig;
import com.yanqu.road.entity.activity.silkroad.config.SilkRoadSeaConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.log.LogSilkRoadFind;
import com.yanqu.road.entity.log.LogSilkRoadRefloat;
import com.yanqu.road.logic.activity.silkroad.refloat.SilkRoadSeaItem;
import com.yanqu.road.logic.activity.silkroad.refloat.SilkRoadSeaScence;
import com.yanqu.road.logic.helper.WeightHelper;
import com.yanqu.road.pb.activity.SilkRoadProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.silkroad.SilkRoadMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.pb.ActivityPb;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.RandomHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class SilkRoadModule extends GeneralModule {

    private UserSilkRoadData userData;

    @Override
    public boolean loadData() {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.SilkRoad.getValue())) {
            return true;
        }
        if (!SilkRoadMgr.isInActivityShowTime()) {
            return true;
        }
        userData = new UserSilkRoadDaoImpl().getUserSilkRoadData(player.getUserId(), SilkRoadMgr.getActivityInfo().getActivityId());
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return true;
    }

    @Override
    public boolean saveData() {
        if (userData == null) {
            return true;
        }
        if (userData.isInsertOption()) {
            new UserSilkRoadDaoImpl().add(userData);
        } else if (userData.isUpdateOption()) {
            new UserSilkRoadDaoImpl().update(userData);
        }
        return true;
    }

    @Override
    public void loginSendMsg() {

    }

    @Override
    public void afterLogin() {
        initUserData();
        syncConfigMsg();
        syncUserMsg();
    }

    public SilkRoadModule(GamePlayer player) {
        super(player);
    }


    public void initUserData() {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.SilkRoad.getValue())) {
            return;
        }
        if (!SilkRoadMgr.isInActivityShowTime()) {
            return;
        }
        if (userData == null || userData.getActivityId() != SilkRoadMgr.getActivityInfo().getActivityId()) {
            userData = new UserSilkRoadData(player.getUserId(), SilkRoadMgr.getActivityInfo().getActivityId());
            userData.setRouteIndex(1);
        } else {
            if (userData.getRouteIndex() == 0) {
                userData.setRouteIndex(1);
            }
        }
    }

    public void syncConfigMsg() {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.SilkRoad.getValue())) {
            return;
        }
        if (!SilkRoadMgr.isInActivityShowTime()) {
            return;
        }

        player.sendPacket(ClientProtocol.U_SILK_ROAD_CONFIG_SYNC, SilkRoadMgr.getConfigMsg(player.getLanguage()));
    }

    public void syncUserMsg() {
        initUserData();
        if (userData == null) {
            return;
        }

        if (!SilkRoadMgr.isInActivityShowTime()) {
            return;
        }
        SilkRoadProto.SilkRoadUserDataSyncMsg.Builder synMsg = ActivityPb.parseSilkRoadUserBuilder(userData,
                SilkRoadMgr.getConfig().getPlaceInfo(userData.getRouteIndex()));

        player.sendPacket(ClientProtocol.U_SILK_ROAD_USER_SYNC, synMsg);
    }

    /**
     * 系统解锁
     */
    public void initSystem() {
        syncConfigMsg();
        syncUserMsg();
    }

    private int checkActivity(ActivityInfo activityInfo) {
        if (activityInfo == null || activityInfo.getType() != eActivityType.SilkRoad.getValue()) {
            return GameErrorCode.E_ACTIVITY_NO_FOUND;
        }
        if (!SystemOpenMgr.systemOpen(player, eSystemId.SilkRoad.getValue())) {
            return GameErrorCode.E_SYSTEM_NO_OPEN;
        }
        if (!ActivityMgr.activityInTime(activityInfo)) {
            return GameErrorCode.E_ACTIVITY_OVER_TIME;
        }
        return 0;
    }

    /**
     * 寻宝
     *
     * @param activityId
     * @param findTimes
     * @return
     */
    public SilkRoadFindResult findTreasure(int activityId, int findTimes) {
        SilkRoadFindResult result = new SilkRoadFindResult();

        if (findTimes != 1 && findTimes != 10) {
            result.setRet(GameErrorCode.E_ACTIVITY_TREASURE_FIND_NUM_ERROR);
            return result;
        }

        ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
        int ret = checkActivity(activityInfo);
        if (ret != 0) {
            return result.setRet(ret);
        }

        if (userData.getEventIds().size() + findTimes > SilkRoadMgr.getConfig().getSILKROAD_EVENT_NUM_LIMIT()) {
            result.setRet(GameErrorCode.E_SILKROAD_EVENT_FULL);
            return result;
        }

        Property consume = new Property();
        int consumeGoodId = SilkRoadMgr.getConfig().getSILKROAD_ITEM_TICKET_NAVIGATION();
        if (1 == findTimes) {
            consume.setGood(consumeGoodId, BigInteger.ONE);
        } else {
            consume.setGood(consumeGoodId, BigInteger.valueOf(9L));   //消耗9个
        }

        //扣除消耗道具
        if (!player.getModule(CurrencyModule.class).removeCurrency(consume, eLogMoneyType.SilkRoad, eLogMoneyType.SilkRoadFindCost)) {
            result.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
            return result;
        }
        //玩家活动数据
        result.setUserData(userData);

//        SilkRoadPlaceProgressInfo placeInfo = SilkRoadMgr.getConfig().getPlaceInfo(userData.getRouteIndex());
//        log.info("玩家{}，寻宝之前的位置{},地点{},位置{}", userData.getUserId(), userData.getRouteIndex(), placeInfo.getPlaceId(), placeInfo.getRoutProgress());

        Property totalRewards = new Property();
        int eventId = 0;
        //1次或10次
        for (int i = 0; i < findTimes; i++) {

            SilkRoadGain gain = findOne(userData);

            totalRewards.addProperty(gain.getRewards());
            //行走步数
            result.getFindStepList().add(gain.getFindStep());
//            log.info("玩家{}，走了{}步", userData.getUserId(), gain.getFindStep());
            //大地点
            if (gain.getPlaceId() != 0) {
                result.getPlaceIdList().add(gain.getPlaceId());
            }

            if (gain.getEventId() != 0) {
                result.addEventId(gain.getEventId());
                userData.addEventId(gain.getEventId());
            }

            result.addAddScore(gain.getAddScore());
        }
//        placeInfo = SilkRoadMgr.getConfig().getPlaceInfo(userData.getRouteIndex());
//        log.info("玩家{}，寻宝之后的位置{},地点{},位置{}", userData.getUserId(), userData.getRouteIndex(), placeInfo.getPlaceId(), placeInfo.getRoutProgress());

        //奖励
        player.getModule(CurrencyModule.class).addCurrency(totalRewards, eLogMoneyType.SilkRoad, eLogMoneyType.SilkRoadFindReward);

        //榜单
        player.notifyListener(eGamePlayerEventType.SilkRoadUserScoreRank.getValue(), userData.getScore());

        //积分只有榜单作用了,不放背包
        totalRewards.addProperty(SilkRoadMgr.getConfig().getEXCHANGE_SCORE_ITEM_ID(), BigInteger.valueOf(result.getAddScore()));

        result.setRewards(PropertyHelper.parsePropertyToString(totalRewards));

        String logReward = PropertyHelper.parsePropertyToString(totalRewards);

        // 日志
        List<Integer> logStepList = new ArrayList<>(result.getFindStepList());
        List<Integer> logPlaceList = new ArrayList<>(result.getPlaceIdList());
        List<Integer> logEventList = new ArrayList<>(result.getEventIds());
        LogSilkRoadFind logTreasureFind = new LogSilkRoadFind(
                activityInfo.getActivityId(),
                getUserId(),
                findTimes,
                logStepList.stream().mapToInt(item -> item).sum(),
                logStepList,
                logPlaceList,
                logEventList,
                logReward,
                userData.getRouteIndex()
        );
        AutoLogMgr.add(logTreasureFind);

        return result;
    }

    /**
     * 寻宝一次
     *
     * @param userData
     * @return
     */
    public SilkRoadGain findOne(UserSilkRoadData userData) {
        SilkRoadGain result = new SilkRoadGain();
        try {
            SilkRoadPlaceProgressInfo oldPlaceInfo = SilkRoadMgr.getConfig().getPlaceInfo(userData.getRouteIndex());

            int randomStep = SilkRoadMgr.getConfig().getRandomStepNum();

            SilkRoadPlaceProgressInfo placeInfo = SilkRoadMgr.getConfig().getPlaceInfo(userData.getRouteIndex() + randomStep);

            //步数 积分奖励
            long addScore = SilkRoadMgr.getConfig().getSILKROAD_STEP_SCORE() * randomStep;

//            Property rewards = new Property(SilkRoadMgr.getConfig().getEXCHANGE_SCORE_ITEM_ID(), BigInteger.valueOf(addScore));
//            result.getRewards().addProperty(rewards);

            //是否大地点
            if (placeInfo.getRoutProgress() == 0) {
                result.setPlaceId(placeInfo.getPlaceId());

                //随机奖励
                Property reward = PropertyHelper.randomPropertyByListList(placeInfo.getSilkRoadPlace().getRewardsList());
                Property specialReward = PropertyHelper.randomPropertyByListList(placeInfo.getSilkRoadPlace().getSpecialRewardsList());
                reward.addProperty(specialReward);
                if (!reward.isNothing()) {
                    //记录奖励
                    result.getRewards().addProperty(reward);
                }
            }

            //随机事件
            long randomValue = RandomHelper.nextLong(1000l);
            if (randomValue < SilkRoadMgr.getConfig().getEventTriggerRate()) {
                int eventId = WeightHelper.getRandomValue(SilkRoadMgr.getConfig().getEventList()).intValue();
                SilkRoadEventConfig event = SilkRoadMgr.getConfig().getEventMap().get(eventId);
                if (event != null) {
                    result.setEventId(eventId);
                }
            }

            if (placeInfo.getRound() > oldPlaceInfo.getRound()) {//圈数奖励
                Property roundReward = PropertyHelper.randomPropertyByListList(SilkRoadMgr.getConfig().getRoundRewards());
                if (!roundReward.isNothing()) {
                    result.getRewards().addProperty(roundReward);
                }
            }

            userData.setRouteIndex(userData.getRouteIndex() + randomStep);
            userData.setScore(userData.getScore() + addScore);
            result.setFindStep(randomStep);
            result.setAddScore(addScore);
            result.setRet(0);

        } catch (Exception e) {
            log.error("findOne", e);
        }
        return result;
    }

    /**
     * 领取事件奖励
     */
    public int getEventReward(int activityId, int eventIdIdx, int choseIndex) {
        ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
        int ret = checkActivity(activityInfo);
        if (ret != 0) {
            return ret;
        }

        if (userData.getEventIds().isEmpty()) {
            return GameErrorCode.E_SILKROAD_EVENT_NOT_FIND;
        }
        Property reward = new Property();
        if (eventIdIdx == 0) {//全部领取
            if (userData.getScore() < SilkRoadMgr.getConfig().getOneKeyEventScoreLimit()){
                return GameErrorCode.E_SILKROAD_ONE_KEY_SCORE_NOT_ENOUGH;
            }
            choseIndex = 1;
            for (Integer eventId : userData.getEventIds()) {
                SilkRoadEventConfig event = SilkRoadMgr.getConfig().getEventMap().get(eventId);
                if (event == null) {
                    return GameErrorCode.E_SILKROAD_EVENT_NOT_FIND;
                }

                reward.addProperty(PropertyHelper.randomPropertyByListList(event.getRewardsRandomList(choseIndex)));
                Property specialReward = PropertyHelper.randomPropertyByListList(event.getSpecialRewardsRandomList(choseIndex));
                reward.addProperty(specialReward);
                if (reward.isNothing()) {
                    return GameErrorCode.E_SILKROAD_EVENT_REWARD_NOT_FIND;
                }
            }

            userData.clearEventIds();

        } else {
            if (eventIdIdx < 0 || eventIdIdx > userData.getEventIds().size()) {
                return GameErrorCode.E_SILKROAD_EVENT_NOT_FIND;
            }
            Integer eventId = userData.getEventIds().get(eventIdIdx - 1);

            SilkRoadEventConfig event = SilkRoadMgr.getConfig().getEventMap().get(eventId);
            if (event == null) {
                return GameErrorCode.E_SILKROAD_EVENT_NOT_FIND;
            }

            reward = PropertyHelper.randomPropertyByListList(event.getRewardsRandomList(choseIndex));
            Property specialReward = PropertyHelper.randomPropertyByListList(event.getSpecialRewardsRandomList(choseIndex));
            reward.addProperty(specialReward);
            if (reward.isNothing()) {
                return GameErrorCode.E_SILKROAD_EVENT_REWARD_NOT_FIND;
            }

            userData.removeEventId(eventIdIdx - 1);
        }

        player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.SilkRoad, eLogMoneyType.SilkRoadEventReward);

        SilkRoadProto.SilkRoadEventRewardRespMsg.Builder respMsg = SilkRoadProto.SilkRoadEventRewardRespMsg.newBuilder();
        respMsg.setRet(0);
        respMsg.setReward(PropertyHelper.parsePropertyToString(reward));

        player.sendPacket(ClientProtocol.U_SILK_ROAD_EVENT_REWARD, respMsg);

        syncUserMsg();


        return 0;
    }

    /**
     * 进入海域
     */
    public int enterSea(int activityId, int seaType) {
        ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
        int ret = 0;
        if (activityInfo == null || activityInfo.getType() != eActivityType.SilkRoad.getValue()) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
        } else if (!SystemOpenMgr.systemOpen(player, eSystemId.SilkRoad.getValue())) {
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
        } else if (!ActivityMgr.activityInShowTime(activityInfo)) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
        }
        if (ret != 0) {
            return ret;
        }
        if (!SilkRoadMgr.getConfig().isExistSea(seaType)) {
            return GameErrorCode.E_SILKROAD_SEA_NOT_FIND;
        }
        List<Integer> remainSeaItemList = userData.getRemainSeaItemList(seaType);
        if (remainSeaItemList.isEmpty()) {
            int mapId = SilkRoadMgr.getConfig().randomSeaMapId(seaType);
            //初始化打捞物
            List<SilkRoadSeaConfig> allSeaRefloat = SilkRoadMgr.getConfig().getAllSeaRefloat(seaType, mapId);
            if (allSeaRefloat.isEmpty()) {
                return GameErrorCode.E_SILKROAD_SEA_NOT_FIND;
            }
            for (SilkRoadSeaConfig sea : allSeaRefloat) {
                remainSeaItemList.add(sea.getId());
                userData.addRemainSeaItem(seaType, sea.getId());
            }

            userData.setMapId(mapId);
        }

        SilkRoadProto.SilkRoadEnterRefloatSeaRespMsg.Builder respMsg = SilkRoadProto.SilkRoadEnterRefloatSeaRespMsg.newBuilder();
        respMsg.setRet(0);
        respMsg.addAllSeaItems(remainSeaItemList);
        respMsg.setSeaId(seaType);

        userData.setNowSea(seaType);

        player.sendPacket(ClientProtocol.U_SILK_ROAD_ENTER_REFLOAT_SEA, respMsg);

        return 0;
    }

    /**
     * 发射鱼钩
     */
    public int launchHook(int activityId, SilkRoadProto.SilkRoadRefloatScenceTemp scenceTempMsg, boolean isOneKey) {
        ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
        int ret = 0;
        if (activityInfo == null || activityInfo.getType() != eActivityType.SilkRoad.getValue()) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
        } else if (!SystemOpenMgr.systemOpen(player, eSystemId.SilkRoad.getValue())) {
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
        } else if (!ActivityMgr.activityInShowTime(activityInfo)) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
        }
        if (ret != 0) {
            return ret;
        }
        int seaType = scenceTempMsg.getSeaId();

        List<Integer> remainSeaItemList = userData.getRemainSeaItemList(seaType);
        if (!isOneKey) {
            for (SilkRoadProto.SilkRoadSeaItemTemp itemTemp : scenceTempMsg.getItemsList()) {
                if (!remainSeaItemList.contains(itemTemp.getItemId())) {
                    return GameErrorCode.E_SILKROAD_SEA_REMAIN_REFLOAT_NOT_FIND;
                }
            }
        } else {
            if (userData.getSeaCount() < 1) {
                return GameErrorCode.E_SILKROAD_ONE_KEY_REFLOAT_NOE_ENOUGH;
            }
        }

        Property cost = new Property();
        if (seaType == 1) {
            if (isOneKey) {
                cost = SilkRoadMgr.getConfig().getSILKROAD_SALVAGE_AUTOMATIC_COST1();
            } else {
                cost = SilkRoadMgr.getConfig().getSILKROAD_SALVAGE_COST1();
            }
        } else {
            if (isOneKey) {
                cost = SilkRoadMgr.getConfig().getSILKROAD_SALVAGE_AUTOMATIC_COST2();
            } else {
                cost = SilkRoadMgr.getConfig().getSILKROAD_SALVAGE_COST2();
            }
        }
        int costCount = cost.getCountByGoodsId(SilkRoadMgr.getConfig().getSILKROAD_ITEM_TICKET_SALVAGE()).intValue();
        int addScore = costCount * SilkRoadMgr.getConfig().getSILKROAD_ITEM_TICKET_SALVAGE_ITEM();

        //保底奖励
        Property baseReward = new Property();

        SilkRoadProto.SilkRoadLaunchHookRespMsg.Builder respMsg = SilkRoadProto.SilkRoadLaunchHookRespMsg.newBuilder();
        respMsg.setRet(0);

        boolean isRefloat = false;
        if (isOneKey) {
            for (Integer refloatId : remainSeaItemList) {
                SilkRoadSeaConfig seaItemConfig = SilkRoadMgr.getConfig().getSeaItemConfig(refloatId);
                if (seaItemConfig != null && seaItemConfig.getRandmoNum() > 0) {//只打捞宝物
                    isRefloat = true;
                    respMsg.addRefloatItemId(refloatId);
                    Property refloatReward = PropertyHelper.randomPropertyByListList(seaItemConfig.getRandomRewards());
                    baseReward.addProperty(refloatReward);
                    for (int i = 0; i < seaItemConfig.getRandmoNum(); i++) {
                        int refloatItemId = WeightHelper.getRandomValue(seaItemConfig.getRandomList()).intValue();
                        SilkRoadItemConfig silkRoadItemConfig = SilkRoadMgr.getConfig().getSilkRoadItemConfig(refloatItemId);
                        if (silkRoadItemConfig != null) {
                            respMsg.addRelicId(refloatItemId);
                            //获得博物
                            userData.addRefloatItem(refloatItemId);
                        }
                    }
                }

                userData.removeRemainSeaItem(seaType, refloatId);
            }
        } else {
            SilkRoadSeaScence silkRoadSeaScence = new SilkRoadSeaScence(scenceTempMsg, SilkRoadMgr.getConfig());

            SilkRoadSeaItem silkRoadSeaItem = silkRoadSeaScence.launchMove();
            if (silkRoadSeaItem != null) {//有勾中物品
                respMsg.setHookX(silkRoadSeaItem.getHookX());
                respMsg.setHookY(silkRoadSeaItem.getHookY());
                if (silkRoadSeaItem.getReturnX() != -1 && silkRoadSeaItem.getReturnY() != -1) {
                    respMsg.setReturnHookX(silkRoadSeaItem.getReturnX());
                    respMsg.setReturnHookY(silkRoadSeaItem.getReturnY());
                }
                if (silkRoadSeaItem.getItemId() != 0) {
                    isRefloat = true;
                    respMsg.addRefloatItemId(silkRoadSeaItem.getItemId());
                    SilkRoadSeaConfig seaItemConfig = SilkRoadMgr.getConfig().getSeaItemConfig(silkRoadSeaItem.getItemId());
                    if (seaItemConfig != null) {
                        Property refloatReward = PropertyHelper.randomPropertyByListList(seaItemConfig.getRandomRewards());
                        baseReward.addProperty(refloatReward);
                        for (int i = 0; i < seaItemConfig.getRandmoNum(); i++) {
                            int refloatItemId = WeightHelper.getRandomValue(seaItemConfig.getRandomList()).intValue();
                            SilkRoadItemConfig silkRoadItemConfig = SilkRoadMgr.getConfig().getSilkRoadItemConfig(refloatItemId);
                            if (silkRoadItemConfig != null) {
                                respMsg.addRelicId(refloatItemId);

                                //获得博物
                                userData.addRefloatItem(refloatItemId);
                            }
                        }
                    }
                    userData.removeRemainSeaItem(seaType, silkRoadSeaItem.getItemId());
                }
            }
        }

        if (isRefloat){
            if (!player.getModule(CurrencyModule.class).removeCurrency(cost, eLogMoneyType.SilkRoad, eLogMoneyType.SilkRoadLaunchHookCost)) {
                return GameErrorCode.E_BAG_ITEM_NO_ENOUGH;
            }

            for (int i = 0; i < costCount; i++) {
                Property randomReward = PropertyHelper.randomPropertyByListList(SilkRoadMgr.getConfig().getRefloatBaseRewards());
                baseReward.addProperty(randomReward);
            }

            //更新博物点
            int achievement = 0;
            for (Map.Entry<Integer, Integer> entry : userData.getRefloatItemMap().entrySet()) {
                int refloatItemId = entry.getKey();
                int num = entry.getValue();
                SilkRoadItemConfig silkRoadItemConfig = SilkRoadMgr.getConfig().getSilkRoadItemConfig(refloatItemId);
                if (silkRoadItemConfig != null) {
                    achievement += silkRoadItemConfig.getAchievementRewards() * num;
                }
            }
            userData.setAchievement(achievement);

            if (ActivityMgr.activityInTime(activityInfo)){
                //更新积分
                userData.setScore(userData.getScore() + addScore);
            }

            player.notifyListener(eGamePlayerEventType.SilkRoadReliceAchieve.getValue(), achievement);
            player.notifyListener(eGamePlayerEventType.SilkRoadUserScoreRank.getValue(), userData.getScore());

            if (!baseReward.isNothing()) {
                respMsg.setReward(PropertyHelper.parsePropertyToString(baseReward));
                player.getModule(CurrencyModule.class).addCurrency(baseReward, eLogMoneyType.SilkRoad, eLogMoneyType.SilkRoadLaunchHookReward);
            }
        }

        boolean isRelicEmpty = true;
        for (Integer refloatItemId : userData.getRemainSeaItemList(seaType)) {
            SilkRoadSeaConfig seaItemConfig = SilkRoadMgr.getConfig().getSeaItemConfig(refloatItemId);
            if (seaItemConfig == null) {
                continue;
            }

            if (seaItemConfig.getRandmoNum() > 0) {
                isRelicEmpty = false;
                break;
            }
        }

        respMsg.setIsRelicEmpty(isRelicEmpty);

        player.sendPacket(ClientProtocol.U_SILK_ROAD_LAUNCH_HOOK, respMsg);

        if (isRelicEmpty) {
            userData.clearAllRemainSeaItem(seaType);
            userData.setSeaCount(userData.getSeaCount() + 1);

            enterSea(activityId, seaType);
        }

        syncUserMsg();

        //日志
        LogSilkRoadRefloat logSilkRoadRefloat = new LogSilkRoadRefloat(
                activityId,
                userData.getUserId(),
                seaType,
                respMsg.getRefloatItemIdList(),
                respMsg.getRelicIdList(),
                userData.getAchievement(),
                isOneKey
        );
        AutoLogMgr.add(logSilkRoadRefloat);

        return 0;
    }

    public UserSilkRoadData getUserData() {
        return userData;
    }
}
